package com.yequan.thread.threadpool.mythreadpoolmanager;

import com.yequan.thread.threadpool.plan.NamedThreadFactory;


/**
 * CPU密集型计算线程池
 *
 * @author yequan
 * @date 2019/12/02
 */
public class CpuIntensiveThreadPoolManager {

    /**
     * 线程个数
     **/
    private static int nThreads = Runtime.getRuntime().availableProcessors();
    /**
     * 实例化CpuIntensiveThreadPoolManager对象
     */
    private static CpuIntensiveThreadPoolManager cpuIntensiveThreadPoolManager = new CpuIntensiveThreadPoolManager();

    /**
     * 线程池管理对象
     */
    private CustomThreadPoolManager customThreadPoolManager;

    /**
     * 线程池构造方法
     */
    private CpuIntensiveThreadPoolManager() {
        customThreadPoolManager = new CustomThreadPoolManager(nThreads, 10000, new NamedThreadFactory("CPU"));
    }

    /**
     * 获取全局唯一实例
     *
     * @return
     */
    public static CpuIntensiveThreadPoolManager getInstance() {
        return cpuIntensiveThreadPoolManager;
    }

    /**
     * 获取线程池管理对象
     *
     * @return
     */
    public CustomThreadPoolManager getCustomThreadPoolManager() {
        return customThreadPoolManager;
    }

}
